package com.justnow;

import java.util.Scanner;

public class Solution01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();

        int res = minLength(str1, str2);
        System.out.println(res);
    }

    private static int minLength(String str1, String str2) {

        if (str1 == null || str2 == null || str1.length() < str2.length()) {
            return 0;
        }

        char[] array1 = str1.toCharArray();
        char[] array2 = str2.toCharArray();

        int[] map = new int[256];

        for (int i = 0; i < array2.length; i++) {
            map[array2[i]]++;
        }

        int left = 0;
        int right = 0;
        int match = array2.length;
        int minLen = Integer.MAX_VALUE;

        while(right < array1.length) {
            map[array1[right]]--;
            if (map[array1[right]] >= 0) {
                match--;
            }
            if (match == 0) {
                while (map[array1[left]] < 0) {
                    map[array1[left++]]++;
                }
                minLen = Math.min(minLen, right - left + 1);
                match++;
                map[array1[left++]]++;
            }
            right++;
        }

        return minLen == Integer.MAX_VALUE ? 0 : minLen;
    }
}
